import unittest
from typing import List


class Solution:
    def maximumCount(self, nums: List[int]) -> int:
        idx = self.binary_search_ge(nums, 0)  # 第一个大于等于0的元素下标，此元素左侧均为负数
        idx_2 = self.binary_search_ge(nums, 1) # 第一个大于等于1的元素下标，此元素及其右侧均为正数
        return max(idx, len(nums) - idx_2)

    def binary_search_ge(self, nums: List[int], target):
        left = -1
        right = len(nums)
        while left + 1 < right:
            mid = (right + left) // 2
            if nums[mid] >= target:
                right = mid
            else:
                left = mid
        return right


class Test(unittest.TestCase):
    def test_case_1(self):
        ret = Solution().maximumCount([-3, -2, -1, 0, 0, 1, 2])
        self.assertEqual(3, ret)
